16. Implement drawCircularClippingExample
23 16 AAK DrawCircularClippingExample SC
Android Developer Documentation
- Canvas class
Here is the code:
private fun drawCircularClippingExample(canvas: Canvas) {
canvas.save()
canvas.translate(columnOne, rowTwo)
// Clears any lines and curves from the path but unlike reset(),
// keeps the internal data structure for faster reuse.
path.rewind()
path.addCircle(
circleRadius,clipRectBottom - circleRadius,
circleRadius,Path.Direction.CCW
)
// The method clipPath(path, Region.Op.DIFFERENCE) was deprecated in
// API level 26. The recommended alternative method is
// clipOutPath(Path), which is currently available in
// API level 26 and higher.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
canvas.clipPath(path, Region.Op.DIFFERENCE)
} else {
canvas.clipOutPath(path)
}
drawClippedRectangle(canvas)
canvas.restore()
}
Note: The method clipPath(path, Region.Op.DIFFERENCE) was deprecated in API level 26. The recommended alternative method is clipOutPath(Path), which is currently available in API level 26 and higher. So be sure to check the SDK version and use the appropriate API.